
#include "../src/winui.h"
#include "dep.h"
#include "App.h"
#include "Cmd.h"
namespace App {

static HWND mainWindow = 0;
static HACCEL acc = 0;

HWND getMainWindow() {
	return mainWindow;
}
void Init(HINSTANCE hInstance, LPTSTR lpCmdLine, int nCmdShow) {
	::OleInitialize(0);
	InitUI();
}

void OnExit() {
	if(acc){
		DestroyAcceleratorTable(acc);
	}
	CleanUI();
	::OleUninitialize();
	mainWindow = 0;
}
int MainLoop(HWND w) {
	mainWindow = w;
	acc = loadAccel();

	MSG msg = { 0 };
	BOOL ret = 0;

	while ((ret = GetMessage(&msg, NULL, 0, 0))) {
		if (ret == -1) {
			//error
			break;
		}
		if (!TranslateAccelerator(w, acc, &msg)) {
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}
	OnExit();
	return (int) msg.wParam;
}

void Exit(int code) {
	PostQuitMessage(code);
}
}
;
